package org.example.test;


import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import org.example.enitiy.User;


import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author ：smart card King
 * @version : 1.0
 * @date : 2023/5/3 14:38
 */
public class listdemo {
    public static void main(String[] args) {

        HashMap<Integer, User> map= new HashMap<>();
        ArrayList<User> list = new ArrayList<>();

        User user = new User(1, "张三", 23, "1998-08-3");
        User user1 = new User(2, "李四", 23, "2000-08-3");
        User user2 = new User(3, "王五", 24, "1998-08-3");
        User user3 = new User(4, "王五", 80, "1902-08-3");
        list.add(user);
        list.add(user1);
        list.add(user2);
        list.add(user3);

        //筛选
        List<User> users = list.stream().filter(x -> "王五".equals(x.getName()))
                .collect(Collectors.toList());

        //取最值
        Optional<User> max = list.stream().min(Comparator.comparing(User::getSex));
         max.ifPresent(u-> System.out.println(u+"-end-"));

         //排序  .reversed() 逆向排序
        Stream<User> sorted = list.stream().
                sorted(Comparator.comparing(User::getBoity));
        sorted.forEach(System.out::println);

        ArrayList<Integer> li = new ArrayList<>();
        li.add(5);
        li.add(4);
        li.add(1);
        li.add(7);

        //条件匹配
        boolean b = li.stream().noneMatch( x->x>5);
        System.out.println(b);

        //返回符合条件的第一个元素

       String str ="汉堡";
        List<String> strs = getLength(str);
        strs.forEach(System.out::println);


        JSONObject abc = JSON.parseObject("success:true");
        String join = CollectionUtil.join(abc.keySet(), ":");
        System.out.println(join);


    }

    public static List<String> getLength(String str){
        return new ArrayList<String>(){{
                add(str);
            }};
    }
}
